# -*- coding: utf-8 -*-
# @Time : 2021/9/17 15:51
# @Author : jiangping
# @Email : jp@gmail.com
# @File : MRYX_SPFL_005.py
# @Project : mryx_test
"""验证查看商品评价"""

from time import sleep
from appium.webdriver.common.mobileby import MobileBy as By
from appium import webdriver
from utils.swipe import Swipe
desired_capabilities = {
    'platformName':'Android',
    'deviceName':'127.0.0.1:62001',
    'platformVersion':'7.1.2',
    'appPackage':'cn.missfresh.application',
    'appActivity':'cn.missfresh.module.main.view.SplashActivity',
    'noReset':True
}
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_capabilities)
sleep(2)
#定位器
#首页
goods_sort_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("分类")')#首页分类
snacks_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("休闲零食")')#休闲零食
nuts_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("坚果炒货")')#坚果炒货
goods_locator = (By.XPATH,'//androidx.recyclerview.widget.RecyclerView'
                          '[@resource-id=\"cn.missfresh.application:id/recycler_view\"]'
                          '/android.widget.RelativeLayout[1]')#第一个商品
evaluation_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().className(\"android.widget.ImageView\")')#用户评价
# 1、点击分类
goods_sort_element = driver.find_element(*goods_sort_locator).click()
sleep(2)

# 2、点击【休闲零食】
driver.find_element(*snacks_locator).click()
sleep(2)
# 3、点击【坚果炒货】
driver.find_element(*nuts_locator).click()
sleep(2)
# 4、点击第一个商品
driver.find_element(*goods_locator).click()
sleep(5)
# 5、上滑页面
sp = Swipe(driver)
sp.up_swipe(start_height_percent=0.6,duration=3)
sleep(3)
# 5、点击【用户评价】
driver.find_element(*evaluation_locator).click()

sleep(5)
driver.quit()